var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isAgree:'1'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var payinfo = JSON.parse(options.payinfo);
    this.setData({
      payinfo: payinfo
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  setIsDefault: function () {
    var isAgree = this.data.isAgree;
    if (isAgree == '1') {
      isAgree = '0';
    }
    else {
      isAgree = '1';
    }
    this.setData({ isAgree: isAgree });
    console.log(this.data.isAgree);
  },
  payVip:function(){
    if (this.data.isAgree != '1'){
      return;
    }
    var payinfo = this.data.payinfo;
    var packagestr = "prepay_id=" + payinfo.prepay_id;
    wx.showLoading({
      title: '',
    });
    wx.requestPayment({
      'appId': 'wx93176ec2a9cee7e1',
      'timeStamp': payinfo.timeStamp,
      'nonceStr': payinfo.nonceStr,
      'package': packagestr,
      'signType': 'MD5',
      'paySign': payinfo.paySign,
      'success': function (res) {
        app.getVipInfo();
        wx.hideLoading();
        wx.showToast({
          title: '支付成功',
          duration: 1000
        });
        var delayid = setTimeout(function () {
          clearTimeout(delayid);
          wx.navigateBack({});
        }, 1000);
      },
      'fail': function (res) {
        wx.hideLoading();
      }
    });
  }
})